package com.qztech.sdk.model.entities;

import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.Ignore;
import androidx.room.PrimaryKey;

import java.util.Arrays;

/**
 * @author:zhanghb
 * @date:2019/1/25
 * @email:2573475062@qq.com
 **/
@Entity(tableName = "eq_channel")
public class EqChannel implements Cloneable {

    @PrimaryKey(autoGenerate = true)
    private long id;

    @ColumnInfo(name = "channel")
    protected int channel;

    @ColumnInfo(name = "settings_id")
    private String settingsId;
    @Ignore
    private int[] gain; //所有gain值

    @Ignore
    private float[] q; //所有q值

    @Ignore
    private int[] freq; //所有q值

    @Ignore
    private int index;

    @ColumnInfo(name = "gain_val")
    private String gainVal = Arrays.toString(gain);

    @ColumnInfo(name = "q_val")
    private String qVal = Arrays.toString(q);

    @ColumnInfo(name = "freq_val")
    private String freqVal = Arrays.toString(freq);

    @ColumnInfo
    private int bypass;


    public EqChannel() {

    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public int getChannel() {
        return channel;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public void setChannel(int channel) {
        this.channel = channel;
    }

    public String getSettingsId() {
        return settingsId;
    }

    public void setSettingsId(String settingsId) {
        this.settingsId = settingsId;
    }

    public int[] getGain() {
        return gain;
    }

    public void setGain(int[] gain) {
        this.gain = gain;
    }

    public float[] getQ() {
        return q;
    }

    public void setQ(float[] q) {
        this.q = q;
    }

    public int[] getFreq() {
        return freq;
    }

    public void setFreq(int[] freq) {
        this.freq = freq;
    }

    public String getGainVal() {

        return gainVal = Arrays.toString(gain);
    }

    public int getBypass() {
        return bypass;
    }

    public void setBypass(int bypass) {
        this.bypass = bypass;
    }

    public void setGainVal(String gainVal) {
        this.gainVal = gainVal;
        if (gainVal == null || gainVal.length() <= 0) return;
        String[] tempGain = gainVal.replace("[", "").replace("]", "").split(",");
        this.gain = new int[tempGain.length];
        try {
            for (int i = 0; i < tempGain.length; i++) {
                this.gain[i] = Integer.parseInt(tempGain[i].trim());
            }
        } catch (Exception ex) {
            System.out.println(" setGainVal ERROR:" + ex);
        }
    }

    public String getQVal() {
        return qVal = Arrays.toString(q);
    }

    public void setQVal(String qVal) {
        this.qVal = qVal;
        if (qVal == null || qVal.length() <= 0) return;
        String[] tempGain = qVal.replace("[", "").replace("]", "").split(",");
        this.q = new float[tempGain.length];
        try {
            for (int i = 0; i < tempGain.length; i++) {
                this.q[i] = Float.parseFloat(tempGain[i].trim());
            }
        } catch (Exception ex) {
            System.out.println(" setQVal ERROR:" + ex);
        }
    }

    public String getFreqVal() {
        return freqVal = Arrays.toString(freq);
    }

    public void setFreqVal(String freqVal) {
        this.freqVal = freqVal;
        if (freqVal == null || freqVal.length() <= 0) return;
        String[] tempGain = freqVal.replace("[", "").replace("]", "").split(",");
        this.freq = new int[tempGain.length];
        try {
            for (int i = 0; i < tempGain.length; i++) {
                this.freq[i] = Integer.parseInt(tempGain[i].trim());
            }
        } catch (Exception ex) {
            System.out.println(" setFreqVal ERROR:" + ex);
        }
    }

    public void init() {
        setQVal(qVal);
        setFreqVal(freqVal);
        setGainVal(gainVal);
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
